package com.wjf.concurrency.example.singleton;

import com.wjf.concurrency.annoations.Rcommend;
import com.wjf.concurrency.annoations.ThreadSafe;

/*
*  枚举模式：最安全
* */
@ThreadSafe
@Rcommend
public class SingletonExample7 {

    //私有的构造函数
    private SingletonExample7(){

    }
    //静态的工厂方法
    public static SingletonExample7 getInstance(){
        return Singleton.INSTANCE.getInstance();
    }

    private enum Singleton{
        INSTANCE;
        private SingletonExample7 singletonExample7;

        // JVM保证这个方法绝对只调用一次
        Singleton(){
            singletonExample7=new SingletonExample7();
        }

        public SingletonExample7 getInstance(){
            return  singletonExample7;
        }
    }


}
